import java.util.Vector;

public class Util {
	public static String replace(String s, String match, String rep) {
		if (s == null)
			return null;
		if (match == null)
			return s;
		if (match.equals(rep))
			return s;
		if (rep == null)
			rep = "";
		int idx = 0;
		String t = s;
		do {
			idx = t.indexOf(match, idx);
			if (idx >= 0) {
				t = t.substring(0, idx) + rep + t.substring(idx + match.length());
				idx += rep.length();
			} else
				break;
		} while (true);
		return t;
	}

	public static String[] splitByWord(String ps, String delim) {
		if (ps == null)
			return null;
		String s = new String(ps);
		int i;
		String subs;
		Vector<String> sa = new Vector<String>(10);
		String[] sb;

		if (delim.length() == 0)
			return (null);
		int dlen = delim.length();

		// s=s.trim();
		while (s.length() > 0) {
			i = s.indexOf(delim);
			if (i >= 0) {
				if (i == 0) {
					subs = "";
				} else {
					subs = s.substring(0, i);
				}
				s = s.substring(i + dlen);
				if (s == null || s.length() == 0) {
					sa.addElement(subs);
					sa.addElement("");
					break;
				}
			} else {
				subs = s;
				s = "";
			}
			// s=s.trim();
			sa.addElement(subs);
		}
		sb = new String[sa.size()];
		sa.copyInto(sb);
		;
		return (sb);
	}

}
